#include <iostream>
#include <stdio.h>
#include <string.h>
using std::cout;
using std::cin;
using std::endl;

const int MAXN = 1e5+7;
int cnt[26][MAXN];
char buf[MAXN];

int main(int argc, char** argv) {
#ifdef hai
    freopen("in.txt", "r", stdin);
#endif
    int n,q,l,r;
    int T;
    cin>>T;
    for (int cas = 1; cas <= T; ++cas) {
        scanf("%d %d", &n, &q);
        scanf("%s", buf+1);
        memset(cnt, 0, sizeof(cnt));
        for (int j=0; j<26; ++j) {
            for (int i=1; i<=n; ++i) {
                if (j == (buf[i] - 'A')) cnt[j][i] = cnt[j][i-1] + 1;
                else cnt[j][i] = cnt[j][i-1];
            }
        }
        printf("Case #%d:\n", cas);
        for (int i=0; i<q; ++i) {
            scanf("%d %d", &l, &r);
            int res = 0;
            for (int j=0; j<26; ++j) {
                if (cnt[j][r] - cnt[j][l-1] > 0) {
                    res = cnt[j][r] - cnt[j][l-1];
                    break;
                }
            }
            printf("%d\n", res);
        }
    }
    return 0;
}
